package com.centaline.androidsalesblog.rx.request;

import com.android.volley.VolleyError;
import com.centaline.androidsalesblog.api.usercenter.CollectInfoListApi;
import com.centaline.androidsalesblog.model.responseobject.CollectInfoListRo;
import com.centanet.framework.interfaces.IResponseListener;

import rx.Observable;
import rx.Subscriber;

/**
 * 收藏数量
 * Created by guilin on 16/3/21.
 */
final class RequestCollectInfoCountOnSubccribe implements Observable.OnSubscribe<CollectInfoListRo> {

    private final Class<?> tag;

    public RequestCollectInfoCountOnSubccribe(Class<?> tag) {
        this.tag = tag;
    }

    @Override
    public void call(final Subscriber<? super CollectInfoListRo> subscriber) {
        CollectInfoListApi collectInfoListApi = new CollectInfoListApi(tag, CollectInfoListRo.class, new IResponseListener<CollectInfoListRo>() {
            @Override
            public void onResponse(CollectInfoListRo collectInfoListRo) {
                if (!subscriber.isUnsubscribed()) {
                    subscriber.onNext(collectInfoListRo);
                }
                subscriber.onCompleted();
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                subscriber.onCompleted();
            }
        });
        collectInfoListApi.setCount(0);
        collectInfoListApi.startRequest();
    }
}
